// 简单验证脚本
const fs = require('fs');

// 读取文件内容
const content = fs.readFileSync('./pages/doctor/appointment_management/appointment_management.js', 'utf8');

// 检查是否有未闭合的括号或引号
function checkBrackets(text) {
  const brackets = [];
  const pairs = { '(': ')', '{': '}', '[': ']', '"': '"', "'": "'" };
  
  for (let i = 0; i < text.length; i++) {
    const char = text[i];
    
    // 跳过注释中的内容
    if (text[i-1] === '/' && text[i] === '/') {
      while (i < text.length && text[i] !== '\n') i++;
      continue;
    }
    
    // 跳过字符串中的内容
    if (char === '"' || char === "'") {
      if (brackets[brackets.length-1] === char) {
        brackets.pop();
      } else {
        brackets.push(char);
      }
    } 
    // 处理括号
    else if (char === '(' || char === '{' || char === '[') {
      brackets.push(char);
    } else if (char === ')' || char === '}' || char === ']') {
      const last = brackets.pop();
      if (pairs[last] !== char) {
        return { error: true, message: `括号不匹配: 在位置${i}附近` };
      }
    }
  }
  
  if (brackets.length > 0) {
    return { error: true, message: `存在未闭合的括号或引号: ${brackets.join(', ')}` };
  }
  
  return { error: false };
}

// 运行检查
const result = checkBrackets(content);
console.log('括号检查结果:', result);

// 检查是否有重复的currentAppointmentId定义
const dataStart = content.indexOf('data:');
const dataEnd = content.indexOf('onLoad', dataStart);
const dataContent = content.substring(dataStart, dataEnd);

const dataCurrentAppointmentIdCount = (dataContent.match(/currentAppointmentId/g) || []).length;
console.log(`data对象中currentAppointmentId出现次数: ${dataCurrentAppointmentIdCount}`);

// 检查是否有多余的", 800);"代码
const extraCodePattern = /wx\.hideLoading\(\)\s*,\s*800\s*\);/;
const hasExtraCode = extraCodePattern.test(content);
console.log(`是否有多余的\", 800);\"代码: ${hasExtraCode}`);

// 输出基本信息
console.log('文件总行数:', content.split('\n').length);
console.log('验证完成');
